<template>
  <div>
    <BasicTable @register="registerTable">
      <!--行内操作-->
      <template #action="{ column, record, index }">
        <TableAction :actions="getTableAction(record)"/>
      </template>
    </BasicTable>
    <!--添加编辑-->
    <BcsDrawer @register="registerDrawer" @success="handleSuccess"/>
  </div>
</template>
<script lang="ts" setup name="bcs-list">
import {BasicTable, TableAction, ActionItem} from '@apps/antd-admin/src/components/Table';
import {useDrawer} from '@apps/antd-admin/src/components/Drawer';
import {useBaseTable} from '@apps/antd-admin/src/hooks';

const [registerDrawer, {openDrawer}] = useDrawer();
import BcsDrawer from './components/BusCarSeriesDrawer.vue';
import {Api} from './data/bcs.api';
import {columns, searchFormSchema} from './data/bcs.data';
const props = defineProps({
  brandId: { type: String, default: "" },
});
//初始化Table
const {prefixCls, tableContext} = useBaseTable({
  designScope: 'bcs-template',
  tableProps: {
    title: '车系表管理',
    columns: columns,
    //主键字段
    rowKey: 'carSeriesId',
    //分页列表接口
    listUrl: Api.page,
    //删除接口
    delUrl: Api.remove,
    //是否显示索引列
    showIndexColumn: true,
    showTableSetting:false,
    //查询form配置
    formConfig: {
      schemas: searchFormSchema,
    },
    showActionColumn:false,
    //操作列配置
    actionColumn: {
      width: 120,
    },
  },
});
const [registerTable, {reload, handleDelete, handleSuccess, handleBatchDelete}, {rowSelection, hasSelectedRows}] = tableContext;

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '编辑',
      icon: 'clarity:note-edit-line',
      onClick: handleEdit.bind(null, record),
    },
  ];
}

/**
 * 下拉操作栏
 */
function getDropDownAction(record): ActionItem[] {
  return [
    {
      label: '删除',
      popConfirm: {
        title: '是否确认删除',
        icon: 'ant-design:delete-outlined',
        confirm: handleDelete.bind(null, record),
      },
    },
  ];
}

/**
 * 新增事件
 */
function handleAdd() {
  openDrawer(true, {
    isUpdate: false,
  });
}

/**
 * 编辑事件
 * @param record
 */
function handleEdit(record) {
  openDrawer(true, {
    record,
    isUpdate: true,
  });
}
</script>
